import { BASE_URL } from '@/config';
import { request } from '@/utils/request';

/**
 * 评价相关接口
 */

// 按商家ID查询评价列表
export function getReviewsByMerchant(merchantId: string, pageNum: number = 1, pageSize: number = 10) {
  return request({
    url: `${BASE_URL}/user/reviews/listByMerchant`,
    method: 'GET',
    params: {
      merchantId,
      pageNum,
      pageSize
    }
  });
}

// 按订单ID查询评价列表
export function getReviewsByOrder(orderId: string) {
  return request({
    url: `${BASE_URL}/user/reviews/listByOrder`,
    method: 'GET',
    params: { orderId }
  });
}

// 根据评价ID获取详情
export function getReviewDetail(reviewId: string) {
  return request({
    url: `${BASE_URL}/user/reviews/${reviewId}`,
    method: 'GET'
  });
}

// 获取评价的回复列表
export function getReviewReplies(reviewId: string) {
  return request({
    url: `${BASE_URL}/user/reviews/${reviewId}/replies`,
    method: 'GET'
  });
}

// 对评价进行回复
export interface ReplyRequest {
  merchantId: number;
  replyContent: string;
  replierType: number;
  replierId: number;
}

export function replyToReview(reviewId: string, data: ReplyRequest) {
  return request({
    url: `${BASE_URL}/user/reviews/${reviewId}/reply`,
    method: 'POST',
    data
  });
}

// 添加评价
export interface AddReviewRequest {
  orderId: number;
  score: number;
  customerId?: number;
  merchantId?: number;
  content?: string;
  images?: string;
  isAnonymous?: number;
}

export function addReview(data: AddReviewRequest) {
  return request({
    url: `${BASE_URL}/user/reviews`,
    method: 'POST',
    data
  });
}